package tianrun.ziguan.api.calculate.config.controller.indicators;

import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tianrun.ziguan.api.calculate.config.dto.request.InstanceSelectionBody;
import tianrun.ziguan.api.calculate.config.service.template.instance.ITIndicatorsInstanceService;
import tianrun.ziguan.api.calculate.config.utils.HttpResponseTools;
import tianrun.ziguan.api.common.core.base.ResultBody;

@RestController
@RequestMapping("/indicators")
@Api(tags = "自定义指标")
public class IndicatorsController {

    private final ITIndicatorsInstanceService indicatorsInstanceService;

    public IndicatorsController(ITIndicatorsInstanceService indicatorsInstanceService) {
        this.indicatorsInstanceService = indicatorsInstanceService;
    }


    @ApiOperation(value = "指标实例变量下拉选择")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/selection")
    public ResponseEntity<ResultBody> selection(@RequestBody InstanceSelectionBody body) {
       return HttpResponseTools.good(ResultBody.of(indicatorsInstanceService.selectValue(body)));
    }
    @ApiOperation(value = "指标实例变量下拉选择v2")
    @ApiResponses({@ApiResponse(code = 200, message = "ok")})
    @PostMapping("/selection/v2")
    public ResponseEntity<ResultBody> selectionV2(@RequestBody InstanceSelectionBody body) {
       return HttpResponseTools.good(ResultBody.of(indicatorsInstanceService.selectValueV2(body)));
    }
}
